﻿using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;

namespace ConsoleApp7.Filter
{
    public class MyResultFilter2 : Attribute, IAsyncActionFilter
    {
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            ControllerActionDescriptor controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
            //IsDefined 判断某个方法是否运用了自定义Attribute
            bool isHave = controllerActionDescriptor.MethodInfo.IsDefined(typeof(NoAttribute),false);
            if (isHave)
            {
                await next();
            }
            else 
            {
                Console.WriteLine("my2 ks");
                await next();
                Console.WriteLine("my2 end");
            }
            
        }
    }
}
